package map.DSU;

import java.util.Scanner;

public class findWay {
    private static int[] father;
    public static void init(int n){
        father = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            father[i] = i;
        }
    }
    public static int find(int u) {
        if (u == father[u]){
            return u;
        } else {
            return find(father[u]);
        }
    }
    public static void join(int u, int v) {
        u = find(u);
        v = find(v);
        if (u != v){
            father[v] = u;
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        init(N);
        for (int i = 0; i < M; i++) {
            int S = sc.nextInt();
            int T = sc.nextInt();
            join(S, T);
        }
        int A = sc.nextInt();
        int B = sc.nextInt();
        if (find(A) == find(B)){
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    }
}
